/*
 *  $Id: ArrowOfWinds.cs 1019 2010-05-12 15:01:25Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Air.Spells {
    public class ArrowOfWinds: SpellCard<Creature> {
        public ArrowOfWinds(): base("001_a_s_arrow_of_winds") {
            Level = CompleteLevel.ReadyForTest;
            Version = 0;
            Element = ElementType.Air;
            Value = 100;
            Target = CreatureTarget.Enemy;
            AddCondition(new MeditationCondition(3, true));
            AddCondition(new DelegateCondition(GetConditionPhrase(), HasVictims));
        }

        private static bool IsVictim(Creature cr) {
            return cr.Card.Element == ElementType.Air && !cr.HasFlag<Affects.Antimagic>();
        }

        private static bool HasVictims(AbstractObject caster, Card card) {
            foreach (Creature cr in caster.Owner.GetCreatures())
                if (IsVictim(cr))
                    return true;
            return false;
        }

        protected override void DoAction(TargetArgs<Creature> args) {
            int damage = 0;
            foreach (Creature cr in args.Player.GetCreatures()) {
                if (IsVictim(cr)) {
                    damage += cr.Health;
                    cr.ReturnToDeck();
                }
            }
            args.Target.DamageBy(NewDamage(args, damage));
        }
    }
}
